-------------------------------------------------------------
--					Add Procedure
-------------------------------------------------------------
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Sales_GetSalesByProductNameAndCustomerName]') AND type in (N'P', N'PC'))
BEGIN
DROP PROCEDURE [Sales_GetSalesByProductNameAndCustomerName]
END
GO

Create Procedure [dbo].[Sales_GetSalesByProductNameAndCustomerName]
(
	@ProductName nvarchar(max),
	@CustomerName nvarchar(max)
)
AS

	SELECT 
	S.SalesID, 
	S.SalesDate,
	S.ProductID,
	P.ProductName,
	C.CustomerName,
	S.SalesNumber,
	S.UnitPrice,
	S.TotalSales,
	S.SalesDescription,
	S.SalesUpdateDate
	from dbo.Products P, dbo.Sales S, dbo.Customers C
	where S.IsDeleted=0 and P.IsDeleted=0 and C.IsDeleted=0
	and P.ProductID=S.ProductID and S.CustomerID=C.CustomerID
	and P.ProductName like '%'+ @ProductName +'%' and C.CustomerName like '%'+ @CustomerName +'%'
	order by S.SalesID, S.SalesDate, P.ProductName
	